﻿@page "/Admin/OnlineUsers"
@attribute [Authorize]
@attribute [TabItemOption(Text ="在线用户",Icon ="fa fa-th")]
@inherits BasePage
@inject ISysOnlineUserService SysOnlineUserService

<div class="overflow-hidden h-100">
    <Table TItem="OnlineUserOutput"
            @ref = "@_table"
            IsPagination="true"
            IsStriped="true"
            IsMultipleSelect="true"
            IsBordered="true"
            IsFixedHeader="true" 
            AllowResizing="true"
            ShowLoading="true"
            ShowColumnList="true"
            ShowCardView="true"
            ShowToolbar="true"
            ShowDefaultButtons="false"
            ShowExtendButtons="true"
            ShowSearch="true"
            ShowEmpty="true" 
            SearchModel="@_search" 
            SearchMode="SearchMode.Top"
            PageItemsSource="@(new int[] { 15, 50 })"
            OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.Account" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.LastLoginIp" />
            <TableColumn @bind-Field="@context.LastTime" Width="180" FormatString="yyyy-MM-dd HH:mm:ss"/>
            <TableColumn @bind-Field="@context.LastLoginBrowser" />
            <TableColumn @bind-Field="@context.LastLoginOs" />
            <TableColumn @bind-Field="@context.TenantName" />
        </TableColumns>
        <RowButtonTemplate>
            <TableCellPopconfirmButton Color="Color.Info" Icon="fa fa-edit" Text="强制下线" OnConfirm="@(() => SysOnlineUserService.ForceExistAsync(context))" />
        </RowButtonTemplate>
        <SearchTemplate>
            <GroupBox Title="搜索条件">
                <div class="row g-3 form-inline">
                    <div class="col-12 col-sm-6">
                        <BootstrapInput @bind-Value="@context.SearchValue" PlaceHolder="请输入账号或姓名" ShowLabel="true"/>
                    </div>
                </div>
            </GroupBox>
        </SearchTemplate>
    </Table>
</div>

@code{
    private Table<OnlineUserOutput>? _table;
    private OnlineUserOutput _search = new();

    private Task<QueryData<OnlineUserOutput>> OnQueryAsync(QueryPageOptions options)
        => SysOnlineUserService.PageAsync(_search.Adapt<OnlineuserPageInput>(options));
}